package com.atguigu.flink05;

import com.atguigu.beans.WaterSensor;
import com.atguigu.func.MySinkFunction;
import com.atguigu.func.WaterSensorMapFunction;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/2/23
 * 该案例演示了自定义sink
 */
public class Flink03_Sink_Custom {
    public static void main(String[] args) throws Exception {
        //TODO 1.基本环境准备
        //1.1 指定流处理环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //1.2 设置并行度
        env.setParallelism(1);
        //TODO 2.从指定的网络端口读取数据
        SingleOutputStreamOperator<WaterSensor> wsDS = env
                .socketTextStream("hadoop102", 8888)
                .map(new WaterSensorMapFunction());

        wsDS.addSink(new MySinkFunction());
        wsDS.print();
        env.execute();
    }
}
